package com.ahzx.company.controller;

import com.ahzx.company.domain.CompanyInfo;
import com.ahzx.company.request.CompanyRequest;
import com.ahzx.company.service.CompanyInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业查询控制层
 * @Author syg
 * @Date 2021/4/26 17:06
 * @Desc To be or not to be,that is a question.
 */
@RestController
@RequestMapping("/company")
public class CompanyInfoController extends BaseController {

    @Autowired
    private CompanyInfoService companyInfoService;

    /**
     * 查询企业列表
     * @return
     */
    @GetMapping
    public TableDataInfo list(CompanyRequest companyRequest) {
        startPage();
        List<CompanyInfo> list = companyInfoService.selectCompanyInfoList(companyRequest);
        return getDataTable(list);
    }

    /**
     * 查询企业详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult detail(@PathVariable String id) {
        CompanyInfo companyInfo = companyInfoService.selectCompanyInfoById(id);
        return AjaxResult.success(companyInfo);
    }

    /**
     * 修改企业信息
     * @param companyInfo
     * @return
     */
    @PostMapping("/update")
    public AjaxResult update(@RequestBody CompanyInfo companyInfo) {
        companyInfoService.updateCompanyInfoById(companyInfo);
        return AjaxResult.success();
    }

    /**
     * 修改企业信息
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable String id) {
        companyInfoService.deleteCompanyInfoById(id);
        return AjaxResult.success();
    }


    /**
     * 企业信息导出
     * @param companyRequest
     * @return
     */
    @Log(title = "企业信息表", businessType = BusinessType.EXPORT)
//    @PreAuthorize("@ss.hasPermi('report:demand:export')")
    @GetMapping("/export")
    public AjaxResult export(CompanyRequest companyRequest) {
        List<CompanyInfo> list = companyInfoService.selectCompanyInfoList(companyRequest);
        ExcelUtil<CompanyInfo> util = new ExcelUtil<>(CompanyInfo.class);
        return util.exportExcel(list, "企业信息表");
    }

}
